package com.world.common.exception;

import cn.hutool.http.HttpStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 业务异常
 *
 * @author WangYX
 * @version 1.0.0
 * @date 2023/06/01 11:23
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private String message;

    /**
     * 空构造方法，避免反序列化问题
     */
    public BusinessException() {
    }

    public BusinessException(String message) {
        this.code = HttpStatus.HTTP_INTERNAL_ERROR;
        this.message = message;
    }

    public BusinessException(Integer code, String message) {
        this.message = message;
        this.code = code;
    }

    public BusinessException setMessage(String message) {
        this.message = message;
        return this;
    }
}
